package com.emapp.lccode.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.emapp.lccode.R
import com.emapp.lccode.bean.DeviceKt
import com.emapp.lccode.databinding.ListitemProjectDeviceBinding

class ProjectDeviceAdapter : BaseQuickAdapter<DeviceKt, ProjectDeviceAdapter.VH>() {

    class VH(
        parent: ViewGroup,
        val binding: ListitemProjectDeviceBinding = ListitemProjectDeviceBinding.inflate(
            LayoutInflater.from(parent.context), parent, false
        ),
    ) : RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
        return VH(parent)
    }

    override fun onBindViewHolder(holder: VH, position: Int, item: DeviceKt?) {
        if (item == null) return
        holder.binding.tvName.text = item.name
        holder.binding.tvState.text = when (item.build_status) {
            "1" -> "未开工"
            "2" -> "建设中"
            "3" -> "已竣工"
            else -> {
                "未知"
            }
        }
        holder.binding.tvState.setTextColor(
            when (item.build_status) {
                "1" -> context.resources.getColor(R.color.red)
                "2" -> context.resources.getColor(R.color.green)
                "3" -> context.resources.getColor(R.color.yellow)
                else -> {
                    context.resources.getColor(R.color.word_black)
                }
            }
        )
        holder.binding.tvNum.text = item.num_code
        holder.binding.tvType.text = item.type_name
    }

}